﻿#include <iostream>
#include <string>  
#include <cctype>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <numbers>
#include <sstream>
#include <cstring>
#include <typeinfo>
#include <tuple>
#include <stdio.h>
#include <variant>
#include <map>
#include <cassert>
#include <memory>
#include <random>
#include <ratio>
#include <chrono>
#include <thread>
#include <mutex>
using namespace std;

#include <iomanip>
using std::setw;

// 函数声明
int max(int num1, int num2);

int sum(int a14, int b14 = 20)
{
    int result14;

    result14 = a14 + b14;

    return (result14);
}

// 要生成和返回随机数的函数
int* getRandom()
{
    static int  r[10];

    // 设置种子
    srand((unsigned)time(NULL));
    for (int i = 0; i < 10; ++i)
    {
        r[i] = rand();
        cout << r[i] << endl;
    }

    return r;
}

int* createArray(int size) 
{
    int* arr = new int[size];
    for (int i21 = 0; i21 < size; i21++) 
    {
        arr[i21] = i21 + 1;
    }
    return arr;
}

double power(double x22, int n22)
{
    double val = 1.0;
    while (n22--)
        val *= x22;
    return val;
}

void displayMessage()
{
    cout << "你好，来自displayMessage函数的问候。\n";
}

int i23 = 10;//全局变量

void fun000(int val000) // fun后面可以加数字
{
    val000 = 100;     //将传进来的参数的值更改为100
}

void modifyValue000(int x000)  // modifyValue后面可以加数字
{
    x000 = 10;
}

void fun0(int& r222)
{
    r222 = 100;  //通过引用改变实参的值
}

void modifyValue0(int& x00) 
{
    x00 = 10;
}

int fun1(int n)
{
    if (n == 0 or n == 1)
        return 1;
    else
        return (n * fun1(n - 1));
}

void fun2(int* p222)
{
    *p222 = 100;  //通过指针p改变实参的值
}

void modifyValue2(int* x222) 
{
    *x222 = 10;
}

void greet(std::string name, std::string greeting = "你好") 
{
    std::cout << greeting << "， " << name << "！" << std::endl;
}

void printNumbers(std::initializer_list<int> numbers) 
{
    for (int num : numbers) 
    {
        std::cout << num << " ";
    }
    std::cout << std::endl;
}

void print(const std::string& message) 
{
    std::cout << message << std::endl;
}

char s1[] = "12345";
char s2[] = "qwe";

int nums33[] = { 1,2,3,4,5 };

int a26 = 24;
long long b26 = 12345678;
double c26 = 3.1415;
string s26;

int n27 = 12345;
char str27[10];

std::tuple<int, int> addAndSubtract(int a29, int b29) 
{
    return std::make_tuple(a29 + b29, a29 - b29);
}

int& getMax(int& a30, int& b30) 
{
    return (a30 > b30) ? a30 : b30;
}

int* createArray31(int size31) // createArray后面可以加数字
{
    int* arr31 = new int[size31];
    for (int i31 = 0; i31 < size31; ++i31) 
    {
        arr31[i31] = i31;
    }
    return arr31;
}

void print32(int x32) // print后面可以加数字
{
    std::cout << "Integer: " << x32 << std::endl;
}

void print32(double x32) // print后面可以加数字
{
    std::cout << "Double: " << x32 << std::endl;
}

void print33(const char* str33) 
{
    std::cout << "字符串： " << str33 << std::endl;
}

void print33(const std::string& str33) 
{
    std::cout << "字符串： " << str33 << std::endl;
}

//内联函数，交换两个数的值
inline void swap(int* a, int* b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

//定义内联函数
inline void swap1(int* a52, int* b52)
{
    int temp52;
    temp52 = *a52;
    *a52 = *b52;
    *b52 = temp52;
}

int factorial(int n34) 
{
    if (n34 == 0) 
    {
        return 1;
    }
    return n34 * factorial(n34 - 1);
}

int factorial35(int n35, int result35 = 1) 
{
    if (n35 == 0) 
    {
        return result35;
    }
    return factorial35(n35 - 1, n35 * result35);
}

int fibonacci(int n36) 
{
    if (n36 <= 1) 
    {
        return n36;
    }
    return fibonacci(n36 - 1) + fibonacci(n36 - 2);
}

int add(int a37, int b37) 
{
    return a37 + b37;
}

int add38(int a38, int b38) 
{
    return a38 + b38;
}

int subtract(int a38, int b38) 
{
    return a38 - b38;
}

void applyFunction(int (*func)(int, int), int a39, int b39) 
{
    int result39 = func(a39, b39);
    std::cout << "Result: " << result39 << std::endl;
}

typedef int (*FuncPtr)(int, int);

void applyFunction40(FuncPtr func, int a40, int b40) 
{
    int result40 = func(a40, b40);
    std::cout << "Result: " << result40 << std::endl;
}

template <typename T>
T add(T a, T b) 
{
    return a + b;
}

template <>
int add<int>(int a43, int b43) 
{
    return a43 + b43 + 1; // 特化版本
}

template <typename T, int N>
T multiply(T a44) 
{
    return a44 * N;
}

class Trace{
    public:
        Trace()
        {
            noisy = 0;
        }
        void print(char* s)
        {
            if (noisy)
            {
                printf("%s", s);
            }
        }
        void on() { noisy = 1; }
        void off() { noisy = 0; }
    private:
        int noisy;
};

class Trace0{
public:
    Trace0()
    {
        noisy = 0;
    }
    void print(char* s0); //类内没有显示声明
    void on() { noisy = 1; }
    void off() { noisy = 0; }
private:
    int noisy;
};
//类外显示定义
inline void Trace0::print(char* s0)
{
    if (noisy)
    {
        printf("%s", s0);
    }
}

class Add{
    public:
        int operator()(int a45, int b45) 
        {
            return a45 + b45;
        }
};

class Add46{
    private:
    int base;
    public:
    Add46(int base) : base(base) {}

    int operator()(int a46) 
    {
        return a46 + base;
    }
};

class Calculator{
public:
    int add(int a47, int b47) 
    {
        return a47 + b47;
    }

    int subtract(int a47, int b47) 
    {
        return a47 - b47;
    }
};

template <typename T, int N = 2>
T multiply48(T a48) 
{
    return a48 * N;
}

template <typename T>
T add49(T a49, T b49) 
{
    return a49 + b49;
}

template <>
int add49<int>(int a49, int b49) 
{
    return a49 + b49 + 1; // 特化版本
}

template <typename T, typename U>
struct Add50{
    static T add50(T a50, U b50) 
    {
        return a50 + b50;
    }
};

template <typename T>
struct Add50<T, int>{
    static T add50(T a50, int b50) 
    {
        return a50 + b50 + 1; // 特化版本
    }
};

int divide(int a51, int b51) 
{
    if (b51 == 0) 
    {
        throw std::runtime_error("Division by zero");
    }
    return a51 / b51;
}

void printMessage(const std::string& message) 
{
    std::cout << message << std::endl;
}

class Score{
    public:
        void setScore(int m, int f);
        void showScore();
    private:
        int mid_exam;
        int fin_exam;
}op1, op2, op3;

void Score::showScore()
{
    cout << "期中成绩: " << mid_exam << endl;
    cout << "期末成绩：" << fin_exam << endl;
}

void Score::setScore(int m, int f)
{
    mid_exam = m;
    fin_exam = f;
}

class Score0 {
public:
    void setScore(int m, int f);
    void showScore();
private:
    int mid_exam;
    int fin_exam;
}op4;

void Score0::showScore()
{
    cout << "期中成绩: " << mid_exam << endl;
    cout << "期末成绩：" << fin_exam << endl;
}

void Score0::setScore(int m, int f)
{
    mid_exam = m;
    fin_exam = f;
}

class Base {
public:
    Base() { std::cout << "姓名\n"; }// 构造函数，用于初始化动态分配的内存
    virtual ~Base() { std::cout << "学号\n"; }// 析构函数，用于释放动态分配的内存
};

class Derived : public Base {
public:
    Derived() { std::cout << "成绩：\n"; }
    ~Derived() { std::cout << "60\n"; }
};

int main()
{
    op1.setScore(60, 60);
    op1.showScore();
    
    Score op2, * sc;
    sc = &op2;
    sc->setScore(61, 61);
    op2.showScore();
    
    op3 = op2;
    op3.showScore();
   
    Score0 op4, * sc0;
    sc0 = &op4;
    sc0->setScore(62, 62);
    op4.showScore();

    try 
    {
        int result51 = divide(58, 2);
        std::cout << "Result: " << result51 << std::endl;
    }
    catch (const std::exception& e) 
    {
        std::cout << "Error: " << e.what() << std::endl;
    }

    int result10000 = Add50<int, int>::add50(3, 5); // 输出 "Result1: 9"
    double result20000 = Add50<double, double>::add50(3.0, 5.0); // 输出 "Result2: 8.0"
    std::cout << "Result1: " << result10000 << ", Result2: " << result20000 << std::endl;

    int result1000 = add49(3, 5); // 输出 "Result1: 9"
    double result2000 = add49(3.0, 5.0); // 输出 "Result2: 8.0"
    std::cout << "Result1: " << result1000 << ", Result2: " << result2000 << std::endl;

    int result1111111 = multiply48<int>(3); // 使用默认参数 N = 2
    int result2222222 = multiply48<int, 5>(3); // 指定参数 N = 5
    std::cout << "Result1: " << result1111111 << ", Result2: " << result2222222 << std::endl; // 输出 "Result1: 6, Result2: 15"

    Calculator calc;
    int result111111 = calc.add(3, 5);
    int result222222 = calc.subtract(3, 5);
    std::cout << "Result1: " << result111111 << ", Result2: " << result222222 << std::endl;

    Add add;
    int result45 = add(3, 5);
    std::cout << "Result: " << result45 << std::endl; // 输出 "Result: 8"

    int result11111 = multiply<int, 5>(3); // 输出 "Result1: 15"
    double result22222 = multiply<double, 2>(3.0); // 输出 "Result2: 6.0"
    std::cout << "Result1: " << result11111 << ", Result2: " << result22222 << std::endl;

    int result1111 = add(3, 5); // 输出 "Result1: 9"
    double result2222 = add(3.0, 5.0); // 输出 "Result2: 8.0"
    std::cout << "Result1: " << result1111 << ", Result2: " << result2222 << std::endl;

    int result111 = add(3, 5); // 输出 "Result1: 8"
    double result222 = add(3.0, 5.0); // 输出 "Result2: 8.0"
    std::cout << "Result1: " << result111 << ", Result2: " << result222 << std::endl;

    auto add41 = [](int a41, int b41) -> int 
    {
        return a41 + b41;
    };

    int result41 = add41(3, 5);
    std::cout << "Result: " << result41 << std::endl; // 输出 "Result: 8"

    int x42 = 10;
    auto add42 = [x42](int a42) -> int {
        return a42 + x42;
        };

    int result42 = add42(5);
    std::cout << "Result: " << result42 << std::endl; // 输出 "Result: 15"

    applyFunction40(add38, 3, 5); // 输出 "Result: 8"
    applyFunction40(subtract, 3, 5); // 输出 "Result: -2"

    applyFunction(add38, 3, 5); // 输出 "Result: 8"
    applyFunction(subtract, 3, 5); // 输出 "Result: -2"

    int (*funcArray[2])(int, int) = { add38, subtract }; // 函数指针数组
    int result1 = funcArray[0](3, 5); // 调用 add
    int result2 = funcArray[1](3, 5); // 调用 subtract
    std::cout << "Result1: " << result1 << ", Result2: " << result2 << std::endl; // 输出 "Result1: 8, Result2: -2"

    int (*func)(int, int) = add38; // 声明并初始化函数指针
    int result = func(3, 5); // 调用函数
    std::cout << "结果： " << result << std::endl; // 输出 "Result: 8"

    int m, n;
    cin >> m >> n;
    cout << m << ", " << n << endl;
    swap(&m, &n);
    cout << m << ", " << n << endl;

    int m52, n52;
    cin >> m52 >> n52;
    cout << m52 << ", " << n << endl;
    swap1(&m52, &n52);
    cout << m52 << ", " << n52 << endl;

    std::cout << "递归函数Factorial of 5（60*2*1）: " << factorial(5) << std::endl;

    std::cout << "递归函数Factorial of 5（5*12*2*1）: " << factorial35(5) << std::endl;

    std::cout << "Fibonacci of 5: " << fibonacci(5) << std::endl;

    print33("你好"); // 调用 print(const char*)
    print33(std::string("郦瀚森")); // 调用 print(const std::string&)

    print32(5); // 调用 print(int)
    print32(5.0); // 调用 print(double)

    int* arr31 = createArray31(5);
    for (int i31 = 0; i31 < 5; ++i31) 
    {
        std::cout << arr31[i31] << " ";
    }
    delete[] arr31; // 释放内存

    int x30 = 10, y30 = 20;
    getMax(x30, y30) = 30;
    std::cout << "x: " << x30 << ", y: " << y30 << std::endl; // 输出 "x: 10, y: 30"

    int sum29, diff29;
    std::tie(sum29, diff29) = addAndSubtract(10, 5);
    std::cout << "Sum: " << sum29 << ", Difference: " << diff29 << std::endl;

    stringstream ss28;
    string s28 = "12345";
    int num28 = 54321;
    ss28 << num28;//将int类型的数据写入字符串流中
    s28 = ss28.str();//将字符串流中的数据转换为string类型
    cout << typeid(s28).name() << " " << num28 << endl;

    sprintf_s(str27, "%d", n27);
    cout << str27 << endl;

    s26 = to_string(a26);
    cout << s26 << endl;
    s26 = to_string(b26);
    cout << s26 << endl;
    s26 = to_string(c26);
    cout << s26 << endl;

    for (int i33 = 0; i33 < sizeof(nums33) / sizeof(int); i33++) 
    {
        cout << nums33[i33] + '0' << " ";
    }

    stringstream ss0;
    string s0 = "12345";
    int num0;
    ss0 << s0;//将字符串读入字符串流 
    ss0 >> num0;//从字符串流中读取数据转换为整数
    cout << typeid(num0).name() << " " << num0 << endl;

    int a25;
    long long b25;
    sscanf_s(s1, "%d", &a25);
    sscanf_s(s2, "%lld", &b25);//转字母会成乱码
    cout << "int:" << a25 << endl;
    cout << "long long:" << b25 << endl;

    int a24 = atoi(s1);
    long long b = atol(s2);
    cout << "int:" << a24 << endl;
    cout << "long long:" << b << endl;

    int n000 = 0;
    fun000(n000); // 尝试通过函数改变n的值
    cout << "n = " << n000;
    cout << "\n" << endl;

    int a000 = 5;
    modifyValue000(a000);
    std::cout << a000 << std::endl; // 输出 5
    cout << "\n" << endl;

    int n222 = 0;
    int& r222n222 = n222;
    fun0(r222n222);    // 传递n的引用rn
    cout << "n222 = " << n222;
    cout << "\n" << endl;

    int a00 = 5;
    modifyValue0(a00);
    std::cout << a00 << std::endl; // 输出 10
    cout << "\n" << endl;

    cout << "4！结果" << fun1(4) << "\n";
    cout << "\n" << endl;

    int n2222 = 0;
    int* p222 = &n2222;
    fun2(p222);  //将指向变量n的指针传入到函数fun
    cout << "n2222 = " << n2222;
    cout << "\n" << endl;

    int a222 = 5;
    modifyValue2(&a222);
    std::cout << a222 << std::endl; // 输出 10
    cout << "\n" << endl;

    greet("郦瀚森"); 
    greet("郦瀚森", "你好");   // 默认参数是指在函数声明中为参数提供默认值。如果调用函数时没有提供相应的参数，将使用默认值

    printNumbers({ 1, 2, 3, 4, 5 }); // 输出 "1 2 3 4 5 "

    std::string msg = "你好，郦瀚森。";
    print(msg); // 输出 "Hello, World!"

    // 局部变量声明
    int a = 10;

    // while 循环执行
    while (a < 20)
    {
        cout << "a 的值：" << a << endl;
        a++;
    }

    // for 循环执行
    for (int a0 = 20; a0 < 30; a0 = a0 + 1)
    {
        cout << "a 的值：" << a0 << endl;
    }

    string str("一些字符串");
    // range for 语句  
    for (auto& c : str)
    {
        c = toupper(c);
    }
    cout << str << endl;

    // 局部变量声明
    int a1 = 30;

    // do 循环执行
    do
    {
        cout << "a 的值：" << a1 << endl;
        a1 = a1 + 1;
    } while (a1 < 40);

    int i, j;
    for (i = 2; i < 100; i++) {
        for (j = 2; j <= (i / j); j++) {
            if (!(i % j)) {
                break; // 如果找到，则不是质数
            }
        }
        if (j > (i / j)) {
            cout << i << " 是质数\n";
        }
    }

    // 局部变量声明
    int a2 = 40;

    // do 循环执行
    do
    {
        cout << "a 的值：" << a2 << endl;
        a2 = a2 + 1;
        if (a2 > 45)
        {
            // 终止循环
            break;
        }
    } while (a2 < 50);

    // 局部变量声明
    int a3 = 46;

    // do 循环执行
    do
    {
        if (a3 == 50)
        {
            // 跳过迭代
            a3 = a3 + 1;
            continue;
        }
        cout << "a 的值：" << a3 << endl;
        a3 = a3 + 1;
    } while (a3 < 56);

    // 局部变量声明
    int a4 = 56;

    // do 循环执行
    LOOP:do
    {
        if (a4 == 60)
        {
        // 跳过迭代
        a4 = a4 + 1;
        goto LOOP;
        }
    cout << "a 的值：" << a4 << endl;
    a4 = a4 + 1;
    } while (a4 < 66);

    // 局部变量声明
    int a5 = 29;

    // 使用 if 语句检查布尔条件
    if (a5 < 66)
    {
        // 如果条件为真，则输出下面的语句
        cout << "a 小于 66" << endl;
    }
    cout << "a 的值是 " << a5 << endl;

    // 局部变量声明
    int a6 = 29;

    // 检查布尔条件
    if (a6 < 20)
    {
        // 如果条件为真，则输出下面的语句
        cout << "a 小于 20" << endl;
    }
    else
    {
        // 如果条件为假，则输出下面的语句
        cout << "a 大于 20" << endl;
    }
    cout << "a 的值是 " << a6 << endl;

    // 局部变量声明
    int a7 = 66;

    // 检查布尔条件
    if (a7 == 10)
    {
        // 如果 if 条件为真，则输出下面的语句
        cout << "a 的值是 10" << endl;
    }
    else if (a7 == 20)
    {
        // 如果 else if 条件为真，则输出下面的语句
        cout << "a 的值是 20" << endl;
    }
    else if (a7 == 30)
    {
        // 如果 else if 条件为真，则输出下面的语句
        cout << "a 的值是 30" << endl;
    }
    else
    {
        // 如果上面条件都不为真，则输出下面的语句
        cout << "没有匹配的值" << endl;
    }
    cout << "a 的准确值是 " << a7 << endl;

    int x8 = 66;

    if (x8 < 75) {
        cout << "x 小于 75" << endl;

        if (x8 < 70) {
            cout << "x 小于 70" << endl;
        }
    }

    // 局部变量声明
    int a9 = 67;
    int b9 = 68;

    // 检查布尔条件
    if (a9 == 67)
    {
        // 如果条件为真，则检查下面的条件
        if (b9 == 68)
        {
            // 如果条件为真，则输出下面的语句
            cout << "a 的值是 67，且 b 的值是 68" << endl;
        }
    }
    cout << "a 的准确值是 " << a9 << endl;
    cout << "b 的准确值是 " << b9 << endl;

    int x10 = 68;

    if (x10 < 70) {
        cout << "x 小于 70" << endl;

        if (x10 < 68) {
            cout << "x 小于 68" << endl;
        }
        else {
            cout << "x 大于等于 68" << endl;
        }
    }
    else {
        cout << "x 大于等于 70" << endl;
    }

    int day = 5;

    switch (day) {
    case 1:
        std::cout << "Monday" << std::endl;
        break;
    case 2:
        std::cout << "Tuesday" << std::endl;
        break;
    case 3:
        std::cout << "Wednesday" << std::endl;
        break;
    case 4:
        std::cout << "周四" << std::endl;
        break;
    case 5:
        std::cout << "周五" << std::endl;
        break;
    case 6:
        std::cout << "Saturday" << std::endl;
        break;
    case 7:
        std::cout << "Sunday" << std::endl;
        break;
    default:
        std::cout << "Invalid day" << std::endl;
    }

    // 局部变量声明
    char grade = 'A';

    switch (grade)
    {
    case 'A':
        cout << "很棒！" << endl;
        break;
    case 'B':
    case 'C':
        cout << "做得好" << endl;
        break;
    case 'D':
        cout << "您通过了" << endl;
        break;
    case 'F':
        cout << "最好再试一下" << endl;
        break;
    default:
        cout << "无效的成绩" << endl;
    }
    cout << "您的成绩是 " << grade << endl;

    int number = 2;

    switch (number) {
    case 1:
        std::cout << "数字是一" << std::endl;
        break;
    case 2:
    case 3:
        std::cout << "数字是二或三" << std::endl;
        break;
    default:
        std::cout << "数字不是一二或三" << std::endl;
    }

    // 局部变量声明
    int a11 = 111;
    int b11 = 222;

    switch (a11) {
    case 111:
        cout << "这是外部 switch 的一部分" << endl;
        switch (b11) {
        case 222:
            cout << "这是内部 switch 的一部分" << endl;
        }
    }
    cout << "a 的准确值是 " << a11 << endl;
    cout << "b 的准确值是 " << b11 << endl;

    // 局部变量声明
    int a12 = 100;
    int b12 = 200;
    int ret;

    // 调用函数来获取最大值
    ret = max(a12, b12);

    cout << "最大值是 " << ret << endl;

    // 局部变量声明
    int a13 = 1;
    int b13 = 2;

    cout << "交换前，a 的值：" << a13 << endl;
    cout << "交换前，b 的值：" << b13 << endl;

    // 调用函数来交换值
    swap(a13, b13);

    cout << "交换后，a 的值：" << a13 << endl;
    cout << "交换后，b 的值：" << b13 << endl;

    // 局部变量声明
    int a14 = 100;
    int b14 = 200;
    int result14;

    // 调用函数来添加值
    result14 = sum(a14, b14);
    cout << "总值是：" << result14 << endl;

    // 再次调用函数
    result14 = sum(a14);
    cout << "总值是：" << result14 << endl;

    int  var1;
    char var2[10];

    cout << "var1 变量的地址： ";
    cout << &var1 << endl;

    cout << "var2 变量的地址： ";
    cout << &var2 << endl;

    int  var3 = 20;   // 实际变量的声明
    int* ip3;        // 指针变量的声明

    ip3 = &var3;       // 在指针变量中存储 var 的地址

    cout << "var变量的值： ";
    cout << var3 << endl;

    // 输出在指针变量中存储的地址
    cout << "存储在ip变量中的地址： ";
    cout << ip3 << endl;

    // 访问指针中地址的值
    cout << "*ip变量的值： ";
    cout << *ip3 << endl;

    // 数字定义
    short  s15;
    int    i15;
    long   l15;
    float  f15;
    double d15;

    // 数字赋值
    s15 = 10;
    i15 = 1000;
    l15 = 1000000;
    f15 = 230.47;
    d15 = 30949.374;

    // 数字输出
    cout << "short  s :" << s15 << endl;
    cout << "int    i :" << i15 << endl;
    cout << "long   l :" << l15 << endl;
    cout << "float  f :" << f15 << endl;
    cout << "double d :" << d15 << endl;

    // 数字定义
    short  s16 = 10;
    int    i16 = -1000;
    long   l16 = 100000;
    float  f16 = 230.47;
    double d16 = 200.374;

    // 数学运算
    cout << "sin(d) :" << sin(d16) << endl;
    cout << "abs(i)  :" << abs(i16) << endl;
    cout << "floor(d) :" << floor(d16) << endl;
    cout << "sqrt(f) :" << sqrt(f16) << endl;
    cout << "pow( d, 2) :" << pow(d16, 2) << endl;

    int i17, j17;

    // 设置种子
    srand((unsigned)time(NULL));

    /* 生成 10 个随机数 */
    for (i17 = 0; i17 < 10; i17++)
    {
        // 生成实际的随机数
        j17 = rand();
        cout << "随机数： " << j17 << endl;
    }

    int n18[10]; // n 是一个包含 10 个整数的数组

    // 初始化数组元素          
    for (int i18 = 0; i18 < 10; i18++)
    {
        n18[i18] = i18 + 100; // 设置元素 i 为 i + 100
    }
    cout << "Element" << setw(13) << "Value" << endl;

    // 输出数组中每个元素的值                     
    for (int j18 = 0; j18 < 10; j18++)
    {
        cout << setw(7) << j18 << setw(13) << n18[j18] << endl;
    }

    // 开头设置宽度为 4，后面的 runoob 字符长度大于 4，所以不起作用
    cout << setw(4) << "runoob" << endl;
    // 中间位置设置宽度为 4，后面的 runoob 字符长度大于 4，所以不起作用
    cout << "runoob" << setw(4) << "runoob" << endl;
    // 开头设置间距为 14，后面 runoob 字符数为6，前面补充 8 个空格
    cout << setw(14) << "runoob" << endl;
    // 中间位置设置间距为 14 ，后面 runoob 字符数为6，前面补充 8 个空格
    cout << "runoob" << setw(14) << "runoob" << endl;

    cout << setfill('*') << setw(14) << "runoob" << endl;

    // 一个带有 5 行 2 列的数组
    int a19[5][2] = { {0,0}, {1,2}, {2,4}, {3,6}, {4,8} };

    // 输出数组中每个元素的值                      
    for (int i19 = 0; i19 < 5; i19++)
        for (int j19 = 0; j19 < 2; j19++)
        {
            cout << "a[" << i19 << "][" << j19 << "]: ";
            cout << a19[i19][j19] << endl;
        }

    // 带有 5 个元素的双精度浮点型数组
    double runoobAarray[5] = { 1000.0, 2.0, 3.4, 17.0, 50.0 };
    double* p20;

    p20 = runoobAarray;

    // 输出数组中每个元素的值
    cout << "使用指针的数组值 " << endl;
    for (int i20 = 0; i20 < 29; i20++)
    {
        cout << "*(p + " << i20 << ") : ";
        cout << *(p20 + i20) << endl;
    }

    cout << "使用 runoobAarray 作为地址的数组值 " << endl;
    for (int i20 = 0; i20 < 29; i20++)
    {
        cout << "*(runoobAarray + " << i20 << ") : ";
        cout << *(runoobAarray + i20) << endl;
    }

    // 一个指向整数的指针
    int* p;

    p = getRandom();
    for (int i = 0; i < 30; i++)
    {
        cout << "*(p + " << i << ") : ";
        cout << *(p + i) << endl;
    }

    int* myArray = createArray(29);
    for (int i21 = 0; i21 < 29; i21++) {
        cout << myArray[i21] << " ";
    }
    cout << endl;
    delete[] myArray; // 释放内存

    float x22, y22;
    cout << "输入底数和指数（两数之间空格分隔）：";
    cin >> x22 >> y22;
    cout << x22 << "的" << y22 << "次方是" << power(x22, y22) << endl;

    cout << "你好，来自mian函数的问候。\n";
    displayMessage(); // 调用displayMessage
    cout << "现在又回到了mian函数。\n";

    cout << i23 << endl;//输出全局变量i值10
    i23 = 5;//为全部变量i赋值
    {
        int i23;//局部变量，局部作用域
        i23 = 7;
        cout << i23 << endl;//输出7
    }
    cout << i23 << endl;//输出5

    char site[9] = { 'l', 'i', 'h', 'a', 'n', 's', 'e', 'n', '\0' };

    cout << "郦瀚森的拼音拼写： ";
    cout << site << endl;

    char str1[13] = "QQ";
    char str2[13] = "bilibili";
    char str3[13];
    int  len;

    // 复制 str1 到 str3
    strcpy_s(str3, str1);
    cout << "strcpy_s( str3, str1) : " << str3 << endl;

    // 连接 str1 和 str2
    strcat_s(str1, str2);
    cout << "strcat_s( str1, str2): " << str1 << endl;

    // 连接后，str1 的总长度
    len = strlen(str1);
    cout << "strlen(str1) : " << len << endl;

    string str4 = "QQ";
    string str5 = "bilibili";
    string str6;
    int  len456;

    // 复制 str4 到 str6
    str6 = str4;
    cout << "str6 : " << str6 << endl;
    
    // 连接 str4 和 str5
    str6 = str4 + str5;
    cout << "str4 + str5 : " << str6 << endl;
    
    // 连接后，str6 的总长度
    len456 = str6.size();
    cout << "str6.size() :  " << len456 << endl;

    Derived d;
    return 0;
}

int max(int num1, int num2)// 函数返回两个数中较大的那个数
{
    int result;// 局部变量声明

    if (num1 > num2)
        result = num1;
    else
        result = num2;

    return result;
}